<!DOCTYPE html>
<html>
<head>
    <title>分类新建</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
    <form class="layui-form" autocomplete="off">
        <div class="mainBox">
            <div class="main-container">
                <div class="main-container">
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入分类名称" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="category-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
    {% include 'admin/common/footer.html' %}
    <script>
        layui.use(['form'], function () {
          var form = layui.form;
          form.on('submit(category-save)', function (data) {
            $.ajax({
              url: '/admin/category/save',
              data: JSON.stringify(data.field),
              dataType: 'json',
              contentType: 'application/json',
              type: 'post',
              success: function (result) {
                if (result.success) {
                  layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name))
                    parent.layui.table.reload('category-table')
                  })
                } else {
                  layer.msg(result.msg, { icon: 2, time: 1000 })
                }
              }
            })
            return false
          })
        })
    </script>
</body>
</html>